package com.chushouya.controller.order.clerk;

import com.chushouya.common.annotations.AuthValidate;
import com.chushouya.common.constant.ServiceType;
import com.chushouya.common.support.Contexts;
import com.chushouya.order.dto.api.clerk.action.*;
import com.general.framework.core.enums.LimitType;
import com.general.framework.core.schema.Response;
import com.general.framework.core.schema.SelectModel;
import com.general.framework.web.annotations.RateLimiter;
import com.chushouya.order.service.api.ClerkOrderActionApiService;
import com.chushouya.order.service.api.ClerkOrderActionCtrlApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Slf4j
@Api(tags = ServiceType.CLERK + "业务员订单操作接口")
@RestController
@RequestMapping(ServiceType.CLERK + "/orderAction")
public class ClerkOrderActionApiController {

    @Resource
    private ClerkOrderActionApiService clerkOrderActionApiService;

    @Resource
    private ClerkOrderActionCtrlApiService clerkOrderActionCtrlApiService;

    @GetMapping("/orderActions")
    @ApiOperation("业务员订单操作")
    @AuthValidate
    public Response<List<ClerkOrderAction>> orderActions(Long orderId) {
        return Response.success(clerkOrderActionCtrlApiService.orderActions(orderId, Contexts.getUserContext().getClerkId()));
    }

    @PostMapping("/accept")
    @ApiOperation("接单")
    @AuthValidate
    public Response<Void> accept(@RequestBody @Valid ClerkAcceptAction accept) {
        accept.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.accept(accept);
        return Response.success();
    }

    @PostMapping("/confirm")
    @ApiOperation("确认订单")
    @AuthValidate
    public Response<Void> confirm(@RequestBody @Valid ClerkConfirmAction confirm) {
        confirm.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.confirm(confirm);
        return Response.success();
    }

    @PostMapping("/visit")
    @ApiOperation("上门确认")
    @AuthValidate
    public Response<Void> visit(@RequestBody @Valid ClerkVisitAction visit) {
        visit.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.visit(visit);
        return Response.success();
    }

    @PostMapping("/cancel")
    @ApiOperation("取消订单")
    @AuthValidate
    @RateLimiter(time = 3, count = 1, limitType = LimitType.IP)
    public Response<Void> cancel(@RequestBody @Valid ClerkCancelAction cancel) {
        cancel.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.cancel(cancel);
        return Response.success();
    }

    @GetMapping("/getPayTypes")
    @ApiOperation("完成订单付款方式")
    @AuthValidate
    public Response<List<SelectModel<Integer>>> getPayTypes(@RequestParam(defaultValue = "0") Long orderId) {
        return Response.success();
    }

    @PostMapping("/complete")
    @ApiOperation("完成订单")
    @AuthValidate
    @RateLimiter(time = 3, count = 1, limitType = LimitType.IP)
    public Response<Void> complete(@RequestBody @Valid ClerkCompleteAction complete) {
        complete.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.complete(complete);
        return Response.success();
    }

    @PostMapping("/editOrder")
    @ApiOperation("修改订单信息")
    @AuthValidate
    public Response<Void> editOrder(@RequestBody @Valid ClerkEditOrderAction editOrder) {
        editOrder.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.editOrder(editOrder);
        return Response.success();
    }

    @PostMapping("/delivery")
    @ApiOperation("订单发货")
    @AuthValidate
    public Response<Void> delivery(@RequestBody @Valid ClerkOrderDeliveryAction delivery) {
        delivery.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.delivery(delivery);
        return Response.success();
    }

    @ApiOperation("预约快递")
    @PostMapping("/reserve")
    public Response<Void> reserve(@RequestBody @Valid ClerkOrderExpressReserveAction reserve) {
        return Response.success();
    }

    @PostMapping("/submitCollection")
    @ApiOperation("提交用户收款信息")
    @AuthValidate
    public Response<Void> submitCollection(@RequestBody @Valid ClerkSubmitCollectionAction submitCollection) {
        submitCollection.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.submitCollection(submitCollection);
        return Response.success();
    }

    @PostMapping("/submitQuality")
    @ApiOperation("提交订单质检")
    @AuthValidate
    public Response<Void> submitQuality(@RequestBody @Valid ClerkSubmitQualityAction submitQuality) {
        submitQuality.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.submitQuality(submitQuality);
        return Response.success();
    }

    @PostMapping("/submitRemark")
    @ApiOperation("订单备注")
    @AuthValidate
    public Response<Void> submitRemark(@RequestBody @Valid ClerkSubmitRemarkAction submitRemark) {
        submitRemark.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.submitRemark(submitRemark);
        return Response.success();
    }

    @PostMapping("/submitUserCert")
    @ApiOperation("提交用户证件信息")
    @AuthValidate
    public Response<Void> submitUserCert(@RequestBody @Valid ClerkSubmitUserCertAction submitUserCert) {
        submitUserCert.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.submitUserCert(submitUserCert);
        return Response.success();
    }

    @ApiOperation("订单重置接口")
    @PostMapping("/resetOrderStatus")
    public Response<Void> resetOrderStatus(@RequestBody @Valid ClerkResetOrderStatusAction resetOrderStatus) {
        resetOrderStatus.setClerkId(Contexts.getUserContext().getClerkId());
        clerkOrderActionApiService.resetOrderStatus(resetOrderStatus);
        return Response.success();
    }



}
